﻿var stateid = $("#stateid").val();
//记录页面bootstrap-table全局变量$table，方便应用
$("#rotationchartTable").bootstrapTable({
    url: reqth+"order/queryOrderAddress/"+stateid,
    method: 'post',                      //请求方式（*）
    striped: true,                      //是否显示行间隔色
    toolbar: '#toolbar',                //工具按钮用哪个容器
    search: true ,                     //是否显示表格搜索
    showRefresh: true,                  //是否显示刷新按钮
    showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
    pagination: true,                   //是否显示分页（*）
    sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
    pageList: [5,10],                    //可供选择的每页的行数（*）
    showColumns: true,                  //是否显示所有的列（选择显示的列）
    minimumCountColumns: 2,             //最少允许的列数
    columns: [{
        title: '序号',
        formatter: function one (value, row, index) {
            return index+1;
        }
    },{
        field: 'orderid',
        title: '订单号',
        sortable: true
    },{
        field: 'orderdate',
        title: '订单生成时间'
    },{
        field: 'totalPrice',
        title: '总价/元'
    },{
        field: 'username',
        title: '用户名'
    },{
        field: 'loginacct',
        title: '账号'
    },{
        field: 'address',
        title: '地址'
    },{
        field: 'name',
        title: '姓名'
    },{
        field: 'addressTelephone',
        title: '手机号'
    },{
        field: 'osState',
        title: '订单状态',
    },{
        field:'id',
        title: '订单操作',
        width: 120,
        align: 'center',
        valign: 'middle',
        formatter:function(value, row, index) {
            var result = "";
            result += "<a href='javascript:;' class='btn btn-xs green'title='查看订单详情'>订单详情</a>";
            if (stateid==2){
                result += "<a href='javascript:;' class='btn btn-xs blue' title='编辑' data-toggle='modal'>发货</a>";
            }
            return result;
        },
        events:{
            'click a[title=查看订单详情]': function (e, value, row, index) {
                layer.open({
                    type: 2,
                    title: '订单详情',
                    shadeClose: true,
                    shade: 0.3,
                    area: ['80%', '80%'],
                    content: reqth+"order/goOrderSpecific/"+row.orderid
                })
                return false;
            }, 'click a[title=编辑]': function (e, value, row, index) {
                layer.confirm("是否要发货", {
                    icon: 3,
                    title: '提示'
                }, function() {
                    $.ajax({
                        type: "POST",
                        url: reqth + "order/updateOrderState",
                        data: {
                            orderid:row.orderid
                        },
                        success: function(result) {
                            if (result.success){
                                $("#rotationchartTable").bootstrapTable('refresh');
                                layer.msg("单号为："+row.orderid+"的商品已发货！", {
                                    time: 2000,
                                    icon: 6,
                                    shift: 6
                                });
                            }else{
                                layer.msg("发货失败,请重新操作！", {
                                    time: 2000,
                                    icon: 6,
                                    shift: 6
                                });
                            }
                        }
                    });
                });
            },
        }
    },]
});
function updateById(){
   cid=$("#cid").val();
   commodityname=$("#commodityname").val();
   commoditypath=$("#commoditypath").val();
   commodityorder=$("#commodityorder").val();
   commoditystate=$("#commoditystate").val();
   statebackdrop=$("#statebackdrop").val();
   catid = $("#catid").val();
    $.ajax({
        type:'post',
        url:reqth+"commodity/update",
        data:{
            cid:cid,
            commodityname:commodityname,
            commoditypath:commoditypath,
            commodityorder:commodityorder,
            commoditystate:commoditystate,
            statebackdrop:statebackdrop,
            catid:catid
        },success:function (result){
            if (result.success){

                layer.msg("修改成功！", {
                    time: 2000,
                    icon: 6,
                    shift: 6
                });
            }else{
                layer.msg("修改失败！", {
                    time: 2000,
                    icon: 5,
                    shift: 6
                });
            }
        }
    })
}
